package com.realdolmen.whiteyellowcross.memory.datastore;

import java.util.ArrayList;
import java.util.List;

import com.realdolmen.whiteyellowcross.model.WaitMonthPlanning;
import com.realdolmen.whiteyellowcross.model.WaitWorkShiftDayPlan;
import com.realdolmen.whiteyellowcross.util.DateTimeHelper;

public class WaitMonthPlanningMemory {

    private static final List<WaitMonthPlanning> waitMonthPlannings = new ArrayList<WaitMonthPlanning>();

    static {
        loadWaitPlannings();
    }

    private static void loadWaitPlannings() {
        for (int i = 0; i <= 11; i++) {
            loadMonthWaitPlanning(2014, i);
        }

    }

    private static void loadMonthWaitPlanning(int year, int month) {
        WaitMonthPlanning waitMonthPlanning = new WaitMonthPlanning(new Long(year),
                new Long(month + 1));

        int daysInMonth = DateTimeHelper.getDaysInMonth(month, year);

        for (int i = 0; i < daysInMonth; i++) {

            List<WaitWorkShiftDayPlan> waitWorkShiftDayPlanningList = new ArrayList<WaitWorkShiftDayPlan>();


            WaitWorkShiftDayPlan morningWaitWorkShiftPlan = WaitWorkShiftPlanMemory
                    .getRandomMorningWaitWorkShiftPlan();

            WaitWorkShiftDayPlan afternoonWaitWorkShiftPlan = WaitWorkShiftPlanMemory
                    .getRandomAfterNoonWaitWorkShiftPlan();
            WaitWorkShiftDayPlan eveningWaitWorkShiftPlan = WaitWorkShiftPlanMemory
                    .getRandomEveningWaitWorkShiftPlan();
            waitWorkShiftDayPlanningList.add(morningWaitWorkShiftPlan);
            waitWorkShiftDayPlanningList.add(afternoonWaitWorkShiftPlan);
            waitWorkShiftDayPlanningList.add(eveningWaitWorkShiftPlan);

            waitMonthPlanning.addWaitDayPlanning(i + 1, waitWorkShiftDayPlanningList);

        }

        waitMonthPlannings.add(waitMonthPlanning);
    }

    public static WaitMonthPlanning getWaitPlanning(int year, int month) {
        for (WaitMonthPlanning waitPlanning : waitMonthPlannings) {
            if (waitPlanning.getYear() == year
                    && waitPlanning.getMonth() == month) {
                return waitPlanning;
            }
        }
        return waitMonthPlannings.get(0);
    }

}
